package day3;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {
//	1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//	求出上面数组中0-9分别出现的次数

	@Test
	public void test1() {
		int[] scores = {0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9};
		int count = 0;
		for (int i = 0; i <= 9; i++) {
			count = 0;
			for (int j = 0; j < scores.length; j++) {
				if (scores[j] == i) {
					count++;
				}
			}
			System.out.println(i + "的个数有：" +count + "个");
		}
		
	}
	
//	2、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//	要求求出其中的奇数个数和偶数个数。

	@Test
	public void test2() {
		int[] scores = {0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9};
		int oddnum = 0;
		int evennum = 0;
		for (int i = 0; i < scores.length; i++) {
			if (scores[i] % 2 != 0) {
				oddnum++;
			} else {
				evennum++;
			}
		}
		System.out.println("奇数有：" + oddnum + "个");
		System.out.println("偶数有：" + evennum + "个");
	}
	
//	3、输入一组学生的成绩，使用数组，然后计算他们的平均值.
	
	@Test
	public void test3() {
		int[] scores = {0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9};
		double sum = 0;
		for (int i = 0; i < scores.length; i++) {
			sum = sum + scores[i];
		}
		System.out.println("平均值为：" + (sum / scores.length));
	}
	
//	题目：一个5位数，判断它是不是回文数。即12321是回文数，个位与万位相同，十位与千位相同。
//	char[] array = ['a' , 'b', 'c', 'b' , 'a'];
	
	@Test
	public void test4() {
		System.out.println("请输入一行字符：");
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		char[] getarray = str.toCharArray();
		int[] array = new int[getarray.length];
		for (int i = 0; i < getarray.length; i++) {
			array[i] = getarray[i];
		}
		boolean isHuiWen = true;
		for (int i = 0; i <= array.length; i++) {// array.length/2 - 1
			if (array[i] != array[array.length - 1 - i]) {
				isHuiWen = false;
				break;
			}
		}
		if (isHuiWen) {
			System.out.println(str + "是回文");
		} else {
			System.out.println(str + "不是回文");
		}
	}
	
//	17、输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。
	
	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		char[] getarray = str.toCharArray();
		int[] array = new int[getarray.length];
		for (int i = 0; i < getarray.length; i++) {
			array[i] = getarray[i];
		}
		int space = 0;
		int num = 0;
		int other = 0;
		int letter = 0;
		for (int j = 0; j < array.length; j++) {
			if (array[j] >= 48 && array[j] <= 57) {
				num++;
			} else if ((array[j] >= 65 && array[j] <= 90) || (array[j] >= 97 && array[j] <= 122)) {
				// (int)array[j]
				letter++;
			} else if (array[j] == 32) {
				space++;
			} else {
				other++;
			}
		}
		System.out.println("英文字母的个数为：" + letter);
		System.out.println("空格的个数为：" + space);
		System.out.println("数字的个数为：" + num);
		System.out.println("其他字符的个数为：" + other);
	}
	
//	18、int[] = {23,4,56,78,99,22,67}找出数组里面的最大值和最小值
	
	@Test
	public void test6() {
		int[] array = {23, 4, 56, 78, 99, 22, 67};
		int max = array[0];
		int min = array[0];
		for (int i = 0; i < array.length; i++) {
			if (array[i] > max) {
				max = array[i];
			}
			if (array[i] < min) {
				min = array[i];
			}
		}
		System.out.println("最大值为：" + max);
		System.out.println("最小值为：" + min); // 棵课稞锞
	}
	
	@Test
	public void test7() {
		int[] array = {40, 17, 21, 1};
		for (int i = 1; i < array.length; i++) {
			for (int j = 0; j < array.length - i; j++) {
				if (array[j] > array[j + 1]) {
					int temp = array[j + 1];
					array[j + 1] = array[j];
					array[j] = temp;
				}
			}
		}
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
	}
	
	@Test
	public void test8() {
		int[] arrays = new int[10];
		Scanner scanner = new Scanner(System.in);
		for (int i = 0; i < arrays.length; i++) {
			int getnum = scanner.nextInt();
			arrays[i] = getnum;
		}
		for (int i = 0; i < arrays.length; i++) {
			System.out.print(arrays[i] + " ");
		}
	}
	
	
}